import {AppDataSource} from './data-source'
import {User} from './entity/User'

AppDataSource.initialize().then(async () => {
    const user = new User()
    user.firstName = 'zhang'
    user.lastName = 'san'
    user.age = 18
    user.email = '13123@qq.com'
    user.isActive = true
    await AppDataSource.manager.save(user)
    console.log('用户保存', user)
    const foundUser = await AppDataSource.manager.findOne(User,{
        where: {id: user.id}
    })
    console.log('找到用户', foundUser)
    if (foundUser) {
        foundUser.age = 28
        await AppDataSource.manager.save(foundUser)
        console.log('更新', foundUser)
    }
    if (foundUser) {
        await AppDataSource.manager.remove(foundUser)
        console.log('删除', foundUser)
    }
})